package main

// 使用astaxie封装 github.com/garyburd/redigo/redis的库goredis
import (
	"fmt"
	"github.com/astaxie/goredis"
)

func main() {
	var client goredis.Client
	// 设置访问
	client.Addr = "test-db.xianshuabao.com:6379"
	client.Password = "123456"

	// 字符串操作
	err := client.Set("test-c", []byte("hello world!"))
	println("set test-c:", err)
	val, err := client.Get("test-c")
	fmt.Println("test-c:", string(val))
	_, err = client.Del("test-c")
	if err != nil {
		fmt.Println("删除test-c失败", err)
	}

	// list
	vals := []string{"go-a", "go-b", "go-c", "go-d", "go-e"}
	for _, v := range vals {
		client.Rpush("list", []byte(v))
	}
	dbvals, _ := client.Lrange("list", 0, 4)
	for i, v := range dbvals {
		println(i, ":", string(v))
	}
	client.Del("list")
}
